<template>
	<view>
		<u-notify ref="uNotify"></u-notify>
		<!-- <u-button type="primary" text="添加保险信息" @click="add"></u-button> -->
		<!-- <u-search v-model="keyword" :show-action="false" @change="searchlist" placeholder="请输入关键字"></u-search> -->
		<u-list @scrolltolower="scrolltolower" v-if="insuranceList != false || status == 'loading'">
			<u-list-item v-for="(item, index) in insuranceList" :key="index">
				<u-cell :title="(index+1)+'、'+ item.InsuranceType" @click="openPage(item.Id)" :name="item.Id">
					<view slot="label" style="font-size: 12px;color: #909193;line-height: 18px;">
						<span>{{'保险公司:' + (item.InsuranceCompany || '') + ' 购买时间:' + (item.InsuranceBuytime || '') 
						+ ' 到期时间:' + (item.InsuranceTimeout || '')}}</span>
					</view>
					<!-- <u-avatar slot="icon" shape="square" size="65"
						:src="item.ImageList[0]? `https://project.gxrunxiang.com/SysFile/download?id=${item.ImageList[0].Id}` : ''"
						customStyle="margin: -3px 5px -3px 0"></u-avatar> -->
				</u-cell>
			</u-list-item>
			<u-loadmore :status="status" v-if="loading" />
		</u-list>
		<u-empty mode="data" icon="https://project.gxrunxiang.com/cdn/list.png" v-else>
		</u-empty>
	</view>
</template>

<script>
	import {
		baseUrl
	} from '@/common/config.js'
	import {
		getinsurancelist,
		addcarapply,
	} from '@/common/api.js'
	export default {
		data() {
			return {
				insuranceList: [],
				keyword: "",
				pageIndex: 1, //当前页数
				pageSize: 20, //页数大小
				totalPage: "", //总页数
				total: 0, //数据总数
				status: 'loadmore', //加载状态
				loading: true,
				user: {},
				keyword: "",
				userfilter: {},
				carId: "",
				applyForm: {
					InsuranceBuytime: "",
					InsuranceTimeout: "",
					range: "",
					remark: "",
				},
			}
		},
		onLoad(option) {
			this.user = JSON.parse(uni.getStorageSync("$userinfo"))
			this.carId = option.Id
		},
		onShow() {
			this.insuranceList = []
			this.getlist()
		},
		methods: {
			openPage(Id) {
				uni.navigateTo({
					url: "insurancedetail?Id=" + Id
				})
			},
			async getlist() {
				this.status = 'loading'
				// let querytype = this.$route.query.querytype
				let para = {
					Parameters: [],
				}
				para.Parameters.push({
					FieldName: "carId",
					ConditionalType: "Equal",
					FieldValue: this.carId,
				})
				para.OrderBys = ['CreateTime desc']
				para.pageSize = this.pageSize
				para.pageIndex = this.pageIndex
				await getinsurancelist(para).then(res => {
					let data = res.data
					this.insuranceList.push(...data)
					this.total = res.count
					this.totalPage = Math.ceil(this.total / this.pageSize)
				})
				if (this.insuranceList.length < this.pageSize) {
					this.loading = false; //如果数据列表小于当前页数，就让加载标签消失
					this.status = 'nomore';
				} else {
					this.status = 'loadmore';
				}
			},
			scrolltolower() {
				// 如果当前页数大于等于总页数，状态修改为没有更多了，不再继续往下执行代码
				if (this.pageIndex >= this.totalPage) {
					this.status = 'nomore';
					return;
				};
				this.status = 'loading'; //状态改为加载中
				this.pageIndex = ++this.pageIndex; //页面新增一页
				this.getlist(); //修改页数后，重新获取数据
			},
			// async searchlist() {
			// 	this.insuranceList = [] //初始化
			// 	this.pageIndex = 1 //初始化当前页数为1
			// 	this.loading = true
			// 	await this.getlist()
			// },
			add() {
				uni.navigateTo({
					url: "addinsurance?CarId=" + this.carId
				})
			},
		},
	}
</script>

<style>

</style>